package wyh.orderservice.controller;

import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import wyh.orderservice.constants.Constants;
import wyh.orderservice.model.OrderInfo;

import java.util.Random;
import java.util.UUID;

@RequestMapping("/order")
@RestController
public class OrderController {
    @Autowired
    RabbitTemplate rabbitTemplate;

    @RequestMapping("/create")
    public String create(){
        String id = UUID.randomUUID().toString();
        String msg = "订单ID：" + id;
        rabbitTemplate.convertAndSend("", Constants.ORDER_QUEUE, msg);
        return "消息发送成功";
    }

    @RequestMapping("/create2")
    public String create2(){
        String id = UUID.randomUUID().toString();
        Random random = new Random();
        String name = "good" + random.nextInt();
        OrderInfo orderInfo = new OrderInfo();
        orderInfo.setId(id);
        orderInfo.setName(name);
        rabbitTemplate.convertAndSend("", Constants.ORDER_QUEUE, orderInfo);
        return "消息发送成功";
    }
}
